<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\AdminController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

// 管理后台路由
Route::prefix('admin')->name('admin.')->group(function () {
    // 登录页面
    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.post');
    
    // 需要认证的管理页面
    Route::middleware(['admin.auth'])->group(function () {
        Route::get('/', [AdminController::class, 'dashboard'])->name('dashboard');
        Route::get('/logout', [AuthController::class, 'logout'])->name('logout');
        
        // 用户管理
        Route::get('/users', [AdminController::class, 'users'])->name('users.index');
        Route::get('/users/export', [AdminController::class, 'exportUsers'])->name('users.export');
        Route::get('/users/{user}', [AdminController::class, 'showUser'])->name('users.show');
        Route::get('/users/{user}/edit', [AdminController::class, 'editUser'])->name('users.edit');
        Route::put('/users/{user}', [AdminController::class, 'updateUser'])->name('users.update');
        Route::delete('/users/{user}', [AdminController::class, 'deleteUser'])->name('users.destroy');
        
        // 车主管理
        Route::get('/car-owners', [AdminController::class, 'carOwners'])->name('car-owners.index');
        Route::get('/car-owners/export', [AdminController::class, 'exportCarOwners'])->name('car-owners.export');
        Route::get('/car-owners/{carOwner}', [AdminController::class, 'showCarOwner'])->name('car-owners.show');
        Route::get('/car-owners/{carOwner}/edit', [AdminController::class, 'editCarOwner'])->name('car-owners.edit');
        Route::put('/car-owners/{carOwner}', [AdminController::class, 'updateCarOwner'])->name('car-owners.update');
        Route::delete('/car-owners/{carOwner}', [AdminController::class, 'deleteCarOwner'])->name('car-owners.destroy');
        
        // 扫码记录
        Route::get('/scan-logs', [AdminController::class, 'scanLogs'])->name('scan-logs.index');
        Route::get('/scan-logs/export', [AdminController::class, 'exportScanLogs'])->name('scan-logs.export');
        Route::get('/scan-logs/{scanLog}', [AdminController::class, 'showScanLog'])->name('scan-logs.show');
        Route::delete('/scan-logs/{scanLog}', [AdminController::class, 'deleteScanLog'])->name('scan-logs.destroy');
        
        // 系统设置
        Route::get('/settings', [AdminController::class, 'settings'])->name('settings');
        Route::post('/settings', [AdminController::class, 'updateSettings'])->name('settings.update');
        
        // 管理员账户管理
        Route::post('/admins', [AdminController::class, 'storeAdmin'])->name('admins.store');
        Route::put('/admins/{admin}', [AdminController::class, 'updateAdmin'])->name('admins.update');
        Route::delete('/admins/{admin}', [AdminController::class, 'deleteAdmin'])->name('admins.destroy');
    });
});
